package sculove.test.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import sculove.java.com.DbUtil;
import sculove.spring.framework.util.ComUtil;

public class DbTestMain {
	public static void main(String[] args) throws Exception {
		/** Oracle DB connection **/
		String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
		String DB_INFO = "jdbc:oracle:thin:@150.1.8.161:1521:DBPIBS1";
		String DB_USR = "IBS_WAS1";
		String DB_PW = "IWAS99";
		
		/** MySql DB connection **/
//		String myDB_DRIVER = "com.mysql.jdbc.Driver";
//		String myDB_INFO = "jdbc:mysql://211.32.193.17:3306/gims?useUnicode=true&amp;characterEncoding=EUC-KR";
//		String myDB_USR = "gims";
//		String myDB_PW = "gims00";

		Log logger = LogFactory.getLog("DBTest");
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
//		int total = 0;
		try {
			conn = DbUtil.getConnection(DB_DRIVER, DB_INFO, DB_USR, DB_PW);	
			conn.setAutoCommit(false);
			pstmt = conn.prepareStatement("select FAX_EMAIL_LINK_NO, TRSMSG_DATA_CTNT from tb_zzz470 where srv_sct_cd ='D' and fax_email_link_rslt_cd = 'R' order by reg_dtm desc");
			rs = pstmt.executeQuery();
			while(rs.next())
			{
				String context = rs.getString("TRSMSG_DATA_CTNT");
				String[] arrContext = context.split("\\^");

				PreparedStatement pstmtUp = null;
				try {
					pstmtUp = conn.prepareStatement("update tb_zzz470 set TRSMSG_DATA_CTNT = ? where FAX_EMAIL_LINK_NO = ?");
					pstmtUp.setString(1, ComUtil.encMD5(arrContext[1]) + "^" + arrContext[1]);
					pstmtUp.setString(2, rs.getString("FAX_EMAIL_LINK_NO"));
					pstmtUp.executeUpdate();
					conn.commit();
				} catch (Exception e) {
					e.printStackTrace();
					conn.rollback();
				} finally {
					DbUtil.close(pstmtUp);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DbUtil.close(rs, pstmt, conn );
		}
		
	}

}
